/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.our.angemc.datatypes;

/**
 *
 * @author piskeiro
 */
public class Terminal extends Symbol{
    private TerminalType type;

    public Terminal(String name, Multiplier multiplier, TerminalType type,boolean notMatch) {
        super(name, multiplier,notMatch);
        this.type = type;
    }

    public TerminalType getType() {
        return type;
    }

    public void setType(TerminalType type) {
        this.type = type;
    }

    @Override
    public String toString(){
        if(type == TerminalType.CHAR){
            //return super.getNotMatchStringRepresentation()+"'"+super.toString()+"'";
            return super.getNotMatchStringRepresentation()+super.toString();
        }else if(type == TerminalType.SEQUENCE){
            String[] parts = super.getName().split("\\.\\.");
            if(parts.length==2){
                //return super.getNotMatchStringRepresentation()+"'"+parts[0]+"'..'"+parts[1]+"'";
                return super.getNotMatchStringRepresentation()+parts[0]+".."+parts[1];
            }else{
                return super.getNotMatchStringRepresentation()+super.toString();
            }
        }else{
            return super.getNotMatchStringRepresentation()+super.toString();
        }
    }

    public Terminal clone(){
        Terminal terminal = new Terminal(this.getName(), this.getMultiplier(), this.type, this.isNotMatch());
        return terminal;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Terminal other = (Terminal) obj;
        if (this.type != other.type && !this.getName().equals(other.getName()) &&(this.type == null || !this.type.equals(other.type))) {
            return false;
        }
        return true;
    }

//    @Override
//    public int hashCode() {
//        int hash = 3;
//        return hash*this.getName().hashCode();
//    }
    
}
